var mysql = require('mysql')

var pool = mysql.createPool({
  host: 'localhost',
  user: 'root',
  password: '',
  port: 3306,
  database: 'zhixin',
  timezone: '08:00'
})

function doMysql(sql,data=[]){
  return new Promise((resolve,reject)=>{
    pool.getConnection((err,connection)=>{
      if(err) throw err
      connection.query(sql,data,(error,result)=>{
        if(error){
          return reject(error)
        }
        resolve(result),
        connection.release()
      })
    })
  })
}

function backText (data, total) {
  return {
    data: data,
    success: true,
    message: "数据请求成功",
    errorCode: 0,
    total: total,
    code: 20000
  }
}

exports.doMysql=doMysql
exports.backText=backText